/**
* $Revision$
* $Date$
*
* This file is part of the Weatherstation-Quick-Access repository software.
* Copyright (C) 2011 Weatherstation-Quick-Access developer team
* See http://code.google.com/p/weatherstation-quick-access/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**/

package gougeon.android.wsqa;

import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.widget.TextView;

public class About {
	    public static AlertDialog create( Context context ) throws NameNotFoundException {
	        // Try to load the a package matching the name of our own package
	        PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA);
	        
	        String versionInfo = pInfo.versionName;
	 
	        String aboutTitle = String.format("About %s", context.getString(R.string.app_name));
	        String versionString = String.format("Version: %s", versionInfo);
	        String aboutText = context.getString(R.string.introduction);
	 
	        // Set up the TextView
	        final TextView message = new TextView(context);
	        // We'll use a spannablestring to be able to make links clickable
	        final SpannableString s = new SpannableString(aboutText);
	 
	        // Set some padding
	        message.setPadding(5, 5, 5, 5);
	        // Set up the final string
	        message.setText(versionString + "\n\n" + s);
	        // Now linkify the text
	        Linkify.addLinks(message, Linkify.ALL);
	 
	        return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.icon).setPositiveButton(
	             context.getString(android.R.string.ok), null).setView(message).create();
	    }
	}
